﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>

    <style>
        .layui-body {
            overflow-y: scroll;
        }
    </style>
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>

    <script src="${ctx}/common/plugins/publicJs/publicJs.js"></script>
    <script src="${ctx}/common/plugins/layuiadmin/laydate/laydate.js"></script>

</head>
<body>
<!--主体内容层-->
<div class="layui-fluid">
	<input type="hidden" id="viewpProduct">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15 layui-form">
            <form >
                <!--输入框内容盒子-->
                <div class="layui-form-item">
	                <div class="layui-col-md2">
                       <div class="layui-input-block">
                           <input type="hidden" id="productionCompanyId"  />
                           <button type="button" class="layui-btn layui-btn-warm"  id="prodictionButton" >生产企业</button>
                           <span style="color: red;overflow-x: hidden" id="companyName"  ></span>
                       </div>
	                </div>
				    <label class="layui-form-label">产品名称：</label>
				    <div class="layui-input-inline">
				      <select name="productName"  class="layui-form" id="selectProductName"  lay-filter="selectProductNameFilter">
				      		<option value="">请选择企业</option>
				      </select>
				    </div>
				     <label class="layui-form-label">生产批次：</label>
				    <div class="layui-input-inline">
				      <select name="quiz2">
				        <option value="">请选择产品</option>
				      </select>
				    </div>
				     <label class="layui-form-label">生产日期：</label>
				     <div class="layui-input-inline">
				      <select name="quiz3">
				        <option value="">请选择生产批次</option>
				        <option value="1">2018-01-01</option>
				        <option value="1">2018-01-01</option>
				      </select>
				     </div>
			    </div>
                <!--通用按钮盒子-->
                <div class="layui-col-md12" style="padding-top: 10px;padding-bottom: 10px">
                    <!--通用table表格-->

                    <div style="float: right;" class="layui-btn-group paramBtn">
                        <button id="reloadDetection" type="button" class="layui-btn layui-btn-sm layui-btn-danger">
                           		 查询
                        </button>
                        <button id="resetDetection" type="reset" class="layui-btn layui-btn-sm layui-btn-danger">
                         		   重置
                        </button>
                    </div>
                </div>
            </form> <!--通用按钮盒子-->

            <table class="layui-table"   lay-data="{ url:'${ctx}/supervise/productionBatch/productionBatchPage', page:true,groups:5,id:'demo1' }" lay-filter="demo1">
                <thead>
                    <tr>
                    <th lay-data="{field:'worksheetId'}">加工单ID</th>
                    <th lay-data="{field:'enterpriseName'}">生产企业</th>
                    <th lay-data="{field:'classifyName'}">产品类型</th>
                    <th lay-data="{field:'productName'}">产品名称</th>
                    <th lay-data="{field:'specifications'}">产品规格</th>
                    <th lay-data="{field:'unit'}">产品单位</th>
                    <th lay-data="{field:'batchCode'}">生产批次</th>
                    <th lay-data="{field:'worksheetDate'}">生产日期</th>
                    <th lay-data="{field:'right',toolbar:'#barDemo'}">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
 <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-sm" lay-event="pickingRecord">溯源信息</a>
</script>
</body>
<script>
	//定义访问集合
    var urlList={
    		 		getProductData:'${ctx}/supervise/traceabilityQuery/queryAllProduct',//产品联动
    		 		getProductBatchData:'${ctx}/supervise/traceabilityQuery/queryAllBatch',//生产批次联动
    		 		traceabilityView:'${ctx}/supervise/traceabilityQuery/traceabilityView',
    		 		queryEnterpriseAll:'${ctx}/supervise/traceabilityQuery/queryEnterpriseAll'
   			    }
    var $=layui.$;
    var form = null;
    layui.use(['tree','layer','table','form'], function () {
        $=layui.$;
        form=layui.form;
        var loading = layer.msg("数据加载中...");
        var table1 = layui.table;
        table1.render({
            done: function () {
                layer.close(loading);
            }
        })
        //监听filter为demo的table中的工具条
        table1.on('tool(demo1)', function (obj) {
            var data = obj.data;
        	console.log(JSON.stringify(data));
			$("#viewpProduct").val(JSON.stringify(data));
			//父页面跳转
			parent.location.href=urlList.traceabilityView+"?worksheetId="+data.worksheetId+"&productId="+data.productId;
        });


        /**
         * 条件查询中的查询按钮
         * */
        $("#reloadDetection").on("click",function(){

        	var ids=$("#productionCompanyId").val().split(",");
        	var jsonParamStr='';
        	if(ids && ids.length>0)
        	{
        		var jsonParam=[];
        		for (var i in ids){
            		jsonParam.push({id:ids[i]});
                }
        		jsonParamStr=JSON.stringify(jsonParam);
        	}
        	//这里以搜索为例
            table1.reload('demo1',{
                where: { //设定异步数据接口的额外参数，任意设
                	productName: $("#productName").val(),
                    productClassifyId: $("#mType").val(),
                    jsonParam: jsonParamStr
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        })
        /**
         * 重置条件查询
         * */
        $("#resetDetection").on("click",function(){
           /*  $("#areaDiv").html("");
            $("#area").val("");
            $("#viewpProduct").val(""); */
            //这里以搜索为例
            table1.reload('demo1',{ where: { //设定异步数据接口的额外参数，任意设
            		productName: ''
                    ,productClassifyId: ''
                    ,productionCompanyName: ''
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        })

        /**
         * 点击生产企业按钮
         */
        $("#prodictionButton").on("click",function(){
            layer.open({
                type: 2,
                title: '生产企业',
                shadeClose: true,
                offset: '10px',
                shade: 0.8,
                area: ['50%', '80%'],
                content: urlList.queryEnterpriseAll+'?companyIds='+$("#productionCompanyId").val()
            });
        })
    });
	//根据企业联动产品信息
    function getProductData(id ){
    	var requestData={enterpriseId:id};
    	var returnData=send(urlList.getProductData,requestData);
    	layui.use(['jquery','form'], function () {
    		$.each(returnData, function(index, obj) {
    			console.dir("加载ing");
    			console.dir(obj);
                var option = $("<option>").val(obj.productId).text(obj.productName);
                $("#selectProductName").append(option);
            });
    		//重新渲染表单
        	layui.form.render();
        	//form.render('select','selectProductNameFilter');
	        /* form1.on('select(selectProductNameFilter)', function(data){
	          	console.log(data.value);
	        }); */
    	});

    }
  //根据企业联动产品信息
    function getProductBatchData(id,code){
	    //请求参数
    	var requestData={productId:id,code:code};
    	 //发送请求
	    var returnData=send(urlList.getProductBatchData,requestData);
	    //处理数据
    	layui.use(['jquery','form'], function () {
    		$.each(returnData, function(index, obj) {
                var option = $("<option>").val(obj.productId).text(obj.productName);
                $("#selectProductName").append(option);
            });
    		//重新渲染表单
        	layui.form.render();
        	//form.render('select','selectProductNameFilter');
	        /* form1.on('select(selectProductNameFilter)', function(data){
	          	console.log(data.value);
	        }); */
    	});

    }
	//发送请求
	function send(url,data){
		var returnData=[];
		layui.use('jquery', function () {
			 $.ajax({
	             url: url,
	             data: data, //请求的附加参数，用json对象
	             method: 'POST',
	             async:false,
	             success: function (res) {
	            	console.log("返回数据："+JSON.stringify(data));
	            	//console.log("服务器返回数据：");
	            	//console.dir( res.data);
	            	returnData=res.data;
	             },
	             error:function(){
	            	 console.log("返回数据:error");
	             }
	         });
		});
		 return returnData;
	}
</script>
</html>



